﻿#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>

//打印名字和学号的函数
void PrintInfo(void)
{
	printf("My Name is : %s\n", "ZHANG");
	printf("My Student ID is : %s\n", "22156558");
}


void main()
{
	char Words[1000][50]= {0};//第一维为单词的个数，第二位保存单词
	int WordsCount[1000]= {0};//Words数组中单词出现的次数
	FILE *MyFile;
	MyFile = fopen("Text file.txt","r");
	int len;
	char c;

	if(MyFile == NULL)
	{
		perror("打开文件时发生错误");
		return(-1);
	}
	int i = 0,j = 0;

	do
	{
		c = fgetc(MyFile);
		printf("%c", c);
		if (c == ' ' || c == ',' || c == '.' || c == '\n')
		{
			//读进来的字符不是空格，逗号，句号，回车
			i++;
			j = 0;
		}
		else
		{
			Words[i][j] = c;
			j++;
		}
	}
	while(!feof(MyFile) && i<1000);

	fclose(MyFile);

	for (int k = 0; k<1000; k++)
	{
		if (Words[k][0] != 0)
		{
			printf("%s\n",Words[k]);
		}
	}

//开始统计词频

}


